﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SistemaHospital.Model;

namespace SistemaHospital.Views
{
    /// <summary>
    /// Interaction logic for HacerPedidoPage.xaml
    /// </summary>
    public partial class HacerPedidoPage : Page
    {
        HospitalEntities entities = new HospitalEntities();
        Producto SelectedProduct;
        public HacerPedidoPage()
        {
            InitializeComponent();
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            SelectedProduct = (Producto)dataGrid1.SelectedItem;
        }

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!String.IsNullOrEmpty(textBox1.Text))
            {
                dataGrid1.ItemsSource = Buscar(textBox1.Text);
            }
            else
                dataGrid1.ItemsSource = entities.Productos.ToList();
        }
        private List<Producto> Buscar(String texto)
        {
            List<Producto> lista = new List<Producto>();
            foreach (var item in entities.Productos.ToList())
            {
                if (item.Nombre.ToLower().Contains(textBox1.Text.ToLower()))
                    lista.Add(item);
            }
            return lista;
        }

    }
}
